package com.ferryc.fegin.hystrix;

import com.ferryc.entity.Stroage;
import com.ferryc.fegin.StroageFeignClient;
import com.ferryc.model.Result;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Ferry Chen on 2019/11/13.
 */

@Component
@Slf4j
public class StroageServiceFallbackFactory implements FallbackFactory<StroageFeignClient> {

    @Override
    public StroageFeignClient create(Throwable e) {
        log.error("fallback,reason:" + e.getMessage());
        return new StroageFeignClient() {
            @Override
            public Result add(String productId, int count) {
                return Result.fail("新增失败");
            }

            @Override
            public Result consume(String productId, int count) {
                return Result.fail("处理失败");
            }

            @Override
            public Result<Stroage> getByProductId(String productId) {
                return Result.fail("查询失败");
            }
        };
    }
}
